package com.john.struts.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.john.struts.annotation.ActionAnnotation;
import com.john.struts.annotation.ForwardAnnotation;
import com.john.struts.form.BaseForm;
import com.john.struts.form.LoginForm;

public class LoginAction implements BaseAction {

	@ActionAnnotation(method = "login", formClass = "com.john.struts.form.LoginForm",
			forwards = {@ForwardAnnotation(name = "success", url = "view/success.jsp"), @ForwardAnnotation(name = "fail", url = "view/fail.jsp")})
	public String execute(HttpServletRequest request, BaseForm form, Map<String, String> actionForward) {
		String name ="fail";
		String forwardUrl =null;
		forwardUrl = actionForward.get(name);
		LoginForm tform = (LoginForm) form;
		if(tform.getName().equals("john")){
			name ="success";
			forwardUrl = actionForward.get(name);
			
		}
		return forwardUrl;
	}
	
}
